home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z8.ADF / Nart / rnd.asm < prev    next >
Assembly Source File  |  1986-07-05  |  1KB  |  46 lines

  1. *\ RND.ASM                                             From: AMIGA.3955
  2. *  :ts=8 bk=0
  3. * Yet Another random number generator.  By Leo Schwab.
  4. * Based on an idea posted on the USENET (Thanks, Sam Dicker!)
  5. * For the MetaComCo assembler
  6. *
  7. * Calling convention:
  8. *  long rnd (range);
  9. *  long range;
  10. *
  11. * Assembling:
  12. *  df1:c/assem rnd.asm -o rnd.o
  13. * 8606.30
  14. */
  15.  
  16.                 section code
  17.                 xdef    _rnd
  18.  
  19. _rnd            lea     rndseed,a0      Get address of seed
  20.                 move.l  4(sp),d1        Get range argument
  21.                 tst.l   d1
  22.                 ble.s   setseed         Go reset seed
  23.  
  24.  
  25.                 move.l  (a0),d0         Get seed
  26.                 ADD.L   D0,D0
  27.                 BHI.S   over
  28.                 EORI.L  #$1D872B41,D0
  29. over
  30.                 move.l  d0,(a0)         Save new seed
  31.                 andi.l  #$ffff,d0       Coerce into word
  32.                 andi.l  #$ffff,d1
  33.                 divu    d1,d0           Divide by range
  34.                 swap    d0               and get remainder (modulus)
  35.                 ext.l   d0
  36.                 rts
  37.  
  38. setseed         neg.l   d1              Probably don't need this
  39.                 move.l  d1,(a0)
  40.                 rts
  41.  
  42.                 section data
  43. rndseed         dc.l    0
  44.                 end
  45.